package leetcode.offer;

/**
 * ClassName: Offer66_ConstructArr
 * Description: leetcode-剑指offer 66 构建乘积数组
 * date: 2021-11-18 22:03
 *
 * @author liyifan
 */
public class Offer66_ConstructArr {
    public int[] constructArr(int[] a) {
        if (a.length == 0)
            return new int[0];
        int[] b = new int[a.length];
        int temp = 1;
        b[0] = 1;
        for (int i = 1; i < a.length;i++) {
            b[i] = b[i - 1] * a[i - 1];
        }

        for (int i = a.length - 2;i >= 0;i--) {
            temp *= a[i + 1];
            b[i] *= temp;
        }
        return b;
    }
}
